<%--@elvariable id="typeId" type="java.lang"--%>
<%--@elvariable id="typeName" type="java.lang"--%>
<%--@elvariable id="typeValue" type="java.lang"--%>
<%--
  Created by IntelliJ IDEA.
  : gaoyang
  Date: 14-4-29
  Time: 下午4:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../includes/common.jsp" %>
    <title>分类值列表</title>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline" action="">
        <label for="userName">用户姓名:</label>
        <input type="text" name="userName" class="input-medium" id="userName" value=""/>
        <label for="collectLowerNumber">收藏数量:</label>
        <input type="text" name="collectLowerNumber" style="width: 50px" id="collectLowerNumber" value=""/>
        ~
        <input type="text" name="collectUpperNumber" style="width: 50px" id="collectUpperNumber" value=""/>
        <label for="registerLowerNumber">注册数量:</label>
        <input type="text" name="registerLowerNumber" style="width: 50px" id="registerLowerNumber" value=""/>
        ~
        <input type="text" name="registerUpperNumber" style="width: 50px" id="registerUpperNumber" value=""/>
        <a class="btn btn-primary" onclick="query()">查询</a>
        <a class="btn btn-primary" onclick="analysis('pieAnalysisUserDo','','用户统计饼图',getSelectIds())">饼图分析</a>
        <a class="btn btn-primary" onclick="analysis('columnAnalysisUserDo','','用户统计柱形图',getSelectIds())">柱图分析</a>
    </form>
    <table id="dataTable"></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentList"
                name="contentList"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function query() {
        listOption.url = basePath + "statistic/listAllUserStatistic";
        listOption.data = "userName=" + $("#userName").val().trim() +
                "&" + "collectLowerNumber=" + $("#collectLowerNumber").val().trim() +
                "&" + "collectUpperNumber=" + $("#collectUpperNumber").val().trim() +
                "&" + "registerLowerNumber=" + $("#registerLowerNumber").val().trim() +
                "&" + "registerUpperNumber=" + $("#registerUpperNumber").val().trim();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function getSelectIds() {
        var ids = "";
        var allBox = $("[name='deleteCheckBox']");
        for (var i = 0; allBox.length > i; i++) {
            var value = allBox[i].getAttribute("value");
            if ($("#" + value).attr("checked") == "checked") {
                ids += value + ",";
            }
        }
        if (ids.length == 0) {
            $.messager.alert(" ", "请选择课件！");
        }
        return ids.substring(0, ids.length - 1);
    }

    function analysis(url, typeName, title, ids) {
        if (ids == "")
            return;

        url = "statistic/" + url;
        var data = "ids=" + ids;
        top.showDialog(url, title, data, 1200, 450);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "课件统计信息列表",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp;<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 200},
                    {field: 'userName', title: '用户姓名', align: 'center', width: 200},
                    {field: 'collectNumber', title: '收藏课件数', sortable: true, align: 'center', width: 200},
                    {field: 'registerNumber', title: '注册课件数', sortable: true, align: 'center', width: 200},
                    {field: 'operate', title: '操作', align: 'center', width: 300 }
                ]
            ],
            sortName: "",
            sortOrder: "asc",
            onSortColumn: onSortColumn
        });
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteCheckBox']").attr("checked", false);
        }
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "collectNumber":
                sortColumn = "collect_number";
                break;
            case "registerNumber":
                sortColumn = "register_number";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function pirAnalysisUser(userId) {
        analysis("pieAnalysisUserLikeDo", "用户喜好分析", "", userId);
    }

    function columnAnalysisUser(userId) {
        analysis("columnAnalysisUserLikeDo", "", "", userId);
    }

    function recommend(userId) {

    }

    function queryFormat(temp) {
        for (var i in temp) {
            var idBtn = "&nbsp;<input type='checkbox' name='deleteCheckBox' id='" + temp[i].userId + "' value='" + temp[i].userId + "'\">&nbsp;";
            temp[i].operate = "<a onclick='pirAnalysisUser(" + temp[i].userId + ")'>饼形分析</a>&nbsp;&nbsp;" +
                    "<a onclick='columnAnalysisUser(" + temp[i].userId + ")'>柱图分析</a>&nbsp;&nbsp;" ;
            temp[i].id = idBtn;
        }
        return temp;
    }

    $(function () {
        parent.browserSizeDeal(document.body.clientHeight);
        initDataGrid();
        query();
    })
</script>